package com.chanyachting.emall.serviceImpl;

import java.util.List;

import com.chanyachting.emall.dao.ShortmessageDAO;
import com.chanyachting.emall.domain.Member;
import com.chanyachting.emall.domain.Shortmessage;
import com.chanyachting.emall.service.ShortmessageService;

public class ShortmessageServiceImpl implements ShortmessageService {
	
	private ShortmessageDAO smDao;

	public ShortmessageServiceImpl() {
		
		this.smDao=new ShortmessageDAO();
	}

	public boolean createShortmessage(Shortmessage sm) {
		
		this.smDao.save(sm);
		
		return true;
	}

	public boolean delShortmessage(Shortmessage sm) {
		
		this.smDao.delete(sm);
		
		return true;
	}

	public boolean delShortmessageButh() {
		// TODO Auto-generated method stub
		return false;
	}

	public List<Shortmessage> getAllShortmessage() {
		
		return this.smDao.find("from Shortmessage");
	}

	public List<Shortmessage> getAllShortmessageByAccess(Member member) {
		
		String args[]={String.valueOf(member.getId())};
		
		return this.smDao.find("from Shortmessage where readerId=?", args);
	}

	public List<Shortmessage> getAllShortmessageBySender(Member member) {
		
		String args[]={String.valueOf(member.getId())};
		
		return this.smDao.find("from Shortmessage where senderId=?", args);
	}

	public Shortmessage getOneShortmessage(Shortmessage sm) {
		
		return (Shortmessage) this.smDao.load(Shortmessage.class, sm.getId());
	}

	public boolean readShortmessage(Shortmessage sm) {
		
		sm.setStatus("01");
		
		this.smDao.update(sm);
		
		return true;
	}

	public boolean sendShortmessage(Shortmessage sm) {
		// TODO Auto-generated method stub
		return false;
	}

	public boolean updateShortmessageStatus(Shortmessage sm) {
		
		this.smDao.update(sm);
		
		return true;
	}

}
